package cn.yiyuan.base.until;

import cn.yiyuan.base.customCode.ResponseCode;
import lombok.Data;

/**
 * @user m
 * @project car_mall_system
 * @date 2023-12-27
 * @package cn.yiyuan.base.until
 */
@Data
public class AjaxResult {
    //成功与否
    private Boolean success;
    //错误信息
    private String message;
    //返回数据
    private Object data;
    //错误码
    private Integer code;

    public static AjaxResult me(){
        return new AjaxResult().setCode(ResponseCode.RESPONSE_CODE_200.getCode())
                               .setMessage(ResponseCode.RESPONSE_CODE_200.getMessage()) ;
    }


    public static AjaxResult success(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.message = "操作成功";
        ajaxResult.success = true;
        return ajaxResult;
    }

    public static AjaxResult success(Object obj){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.message = "操作成功";
        ajaxResult.success = true;
        ajaxResult.data = obj;
        return ajaxResult;
    }

    public static AjaxResult success(Object obj,String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.message = msg;
        ajaxResult.success = true;
        ajaxResult.data = obj;
        return ajaxResult;
    }

    public static AjaxResult error(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.message = "操作失败";
        ajaxResult.success = false;
        return ajaxResult;
    }

    public static AjaxResult error(String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.message = msg;
        ajaxResult.success = false;
        return ajaxResult;
    }

    public Boolean getSuccess(){
        return success;
    }
    public AjaxResult setSuccess(Boolean success){
        this.success = success;
        return this;
    }

    public String getMessage(){
        return message;
    }
    public AjaxResult setMessage(String message){
        this.message = message;
        return this;
    }

   public Integer getCode(){
        return code;
   }
   public AjaxResult setCode(Integer code){
        this.code = code;
        return this;
   }
   public Object getData(){
        return data;
   }
   public AjaxResult setData(Object data){
        this.data = data;
        return this;
   }
}
